package com.situ.blog.service.impl;

import com.situ.blog.dao.IUserDao;
import com.situ.blog.dao.impl.UserDaoImpl;
import com.situ.blog.pojo.entity.User;
import com.situ.blog.pojo.query.UserQuery;
import com.situ.blog.service.IUserService;
import com.situ.blog.util.PageInfo;

import java.util.List;

public class UserServiceImpl implements IUserService {
    private IUserDao userDao = new UserDaoImpl();

    @Override
    public User login(String name, String password) {
        return userDao.login(name,password);
    }

    @Override
    public PageInfo selectByPage(UserQuery userQuery) {
        List<User> list = userDao.selectByPage(userQuery);
        int totalCount = userDao.selectTotalCount(userQuery);

        return PageInfo.ok(totalCount,list);
    }

    @Override
    public void deleteById(int id) {
        userDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            userDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(User user) {
        userDao.add(user);
    }

    @Override
    public User selectById(int id) {
        return userDao.selectById(id);
    }

    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Override
    public void updateStatus(int id, int status) {
        userDao.updateStatus(id,status);
    }
}
